package top.gbyun;

import akka.actor.Actor;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import top.gbyun.core.ActorSystemContext;
import top.gbyun.core.entity.FlowInfo;
import top.gbyun.core.entity.NodeInfo;
import top.gbyun.engine.actor.FlowActor;
import top.gbyun.node.NodeA;
import top.gbyun.node.NodeB;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * Hello world!
 *
 */
public class EngineApp
{
    public static void main( String[] args )
    {
        ActorSystem system = ActorSystem.create("gb-flow");

        try {
            // Create top level supervisor
            FlowInfo flowInfo = new FlowInfo();
            flowInfo.setId("a001");
            flowInfo.setName("首个流程");

            // NODEA----->NODEB
            NodeInfo nodeA = new NodeInfo();
            nodeA.setId("nodea01");
            nodeA.setName("节点A");
            nodeA.setFrom(null);
            ArrayList<String> nodeaTos = new ArrayList<>();
            nodeaTos.add("nodeb01");
            nodeA.setTo(nodeaTos);
            nodeA.setType("top.gbyun.node.NodeA");
            nodeA.setTypeClass(NodeA.class);

            NodeInfo nodeB = new NodeInfo();
            nodeB.setId("nodeb01");
            nodeB.setName("节点A");
            ArrayList<String> nodebFroms = new ArrayList<>();
            nodebFroms.add(nodeA.getId());
            nodeB.setFrom(nodebFroms);
            nodeB.setTo(null);
            nodeB.setType("top.gbyun.node.NodeB");
            nodeA.setTypeClass(NodeB.class);

            Map<String, NodeInfo> nodeInfoMap = new HashMap<>();
            nodeInfoMap.put(nodeA.getId(), nodeA);
            nodeInfoMap.put(nodeB.getId(), nodeB);


            flowInfo.setNodeMap(nodeInfoMap);
            ActorSystemContext actorSystemContext = new ActorSystemContext();

            ActorRef flowActor = system.actorOf(FlowActor.props(actorSystemContext,flowInfo), "a001");
            flowActor.tell("test", Actor.noSender());
            System.in.read();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            system.terminate();
        }
    }
}
